#include "m_studentupdate.h"
#include "ui_m_studentupdate.h"
#include "m_studentmanage.h"

extern QString global_id;

m_studentUpdate::m_studentUpdate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::m_studentUpdate)
{
    ui->setupUi(this);
    ui->sidEdit->setText(global_id);
    _query();//显示信息

}

m_studentUpdate::~m_studentUpdate()
{
    delete ui;
}

void m_studentUpdate::_query(){
    QString str=QString("select * from student where sid='%1'").arg(global_id);
    QSqlQuery query;
    query.exec(str);
    if(query.next()){
        ui->snameEdit->setText(query.value(1).toString());
        ui->ssexEdit->setText(query.value(2).toString());
        ui->sphoneEdit->setText(query.value(3).toString());
        ui->scollegeEdit->setText(query.value(4).toString());
        ui->sdeptEdit->setText(query.value(5).toString());
        ui->sroomEdit->setText(query.value(6).toString());
        ui->sbuildEdit->setText(query.value(7).toString());
        ui->spwdEdit->setText(query.value(8).toString());
    }
}

void m_studentUpdate::on_confirmBtn_accepted()
{
    QSqlQuery query;
    QString sid=ui->sidEdit->text();
    QString sname=ui->snameEdit->text();
    QString ssex=ui->ssexEdit->text();
    QString sphone=ui->sphoneEdit->text();
    QString scollege=ui->scollegeEdit->text();
    QString sdept=ui->sdeptEdit->text();
    QString sroomid=ui->sroomEdit->text();
    QString sbuildid=ui->sbuildEdit->text();
    QString spwd=ui->spwdEdit->text();

    QString str=QString("update  student set sid='%1',sname='%2',ssex='%3',sphone='%4',scollege='%5',sdept='%6',sroomid='%7',sbuildid='%8',spwd='%9' "
                        "where sid='%10'").
            arg(sid).arg(sname).arg(ssex).arg(sphone).arg(scollege).arg(sdept).arg(sroomid).arg(sbuildid).arg(spwd).arg(sid);
    qDebug()<<str;
    if(query.exec(str)==true){
        QMessageBox::information(NULL,"tips","修改成功");
        this->close();
    }
    else QMessageBox::warning(NULL,"Error","修改失败，请检查是否有内容写错");
}

